<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>首页</title>
    <!-- 注意点，必须先引用vue.js，再引用element-ui的index.js，因为element-ui是基于vue.js实现的 -->
    <script src="./js/vue.js"></script>
    <script src="./element-ui/lib/index.js"></script>
    <link rel="stylesheet" href="./element-ui/lib/theme-chalk/index.css">

    <style>
        #app {
            width: 100%;
            height: 100%;
            position: relative;
            margin-top: 25%;
        }

        .upload-area {
            position: absolute;
            left: 50%;
            top: 100%;
            transform: translate(-50%, -50%);
        }
    </style>
</head>
<body>

<div id="app">
    <el-upload
            class="upload-area"
            ref="upload"
            drag
            action="/common/upload"
            :show-file-list="false"
            :on-success="handleUploadSuccess">
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip" slot="tip">上传文件大小，不超过500M</div>
    </el-upload>
</div>
</body>
<script>
    new Vue({
        el: "#app",
        methods: {
            handleUploadSuccess(response, file, fileList) {
                if (response.code === 0) {
                    this.$message.error(response.msg || '操作失败');
                } else {
                    const fileUrl = file.response.data.url;
                    console.log(`上传地址：${fileUrl}`)
                    this.$message.success("上传成功");
                }
            }
        }
    });
</script>
</html>